<!doctype html>
<html lang="zh-CN">
<head><meta name="generator" content="Hexo 3.8.0">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=11,IE=10,IE=9,IE=8">
    <meta name="baidu-site-verification" content="dIcXMeY8Ya">
    
    <title>Docker 部署 | blog</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
    <meta name="keywords" content="Jim, 服务端, Java, Java开发">
    <meta name="description" content="Jim个人学习记录">

    
    <link rel="alternative" href="/atom.xml" title="blog" type="application/atom+xml">
    
    
    <link rel="shortcut icon" href="/favicon.ico">
    
    <link rel="stylesheet" href="/css/style.css">
    <!--[if lt IE 9]>
    <script src="/js/html5.js"></script>
    <![endif]-->
    
<script>
    var _hmt = _hmt || [];
    (function() {
        var hm = document.createElement("script");
        hm.src = "//hm.baidu.com/hm.js?fd459238242776d173cdc64918fb32f2";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>


</head>
</html>
<body class="home">
    <!--[if lt IE 9]>
    <div class="browsehappy">
        当前网页 <strong>不支持</strong>
        你正在使用的浏览器. 为了正常的访问, 请 <a href="http://browsehappy.com/">升级你的浏览器</a>.
    </div>
    <![endif]-->

    <!-- 博客头部 -->
    <header class="header">
    <section class="container header-main">
        <div class="logo">
            <a href="/">
                <div class="cover">
                    <span class="name">blog</span>
                    <span class="description"></span>
                </div>
            </a>
        </div>
        <div class="dropnav icon-paragraph-justify" id="JELON__btnDropNav"></div>
        <ul class="menu hidden" id="JELON__menu">
            
            <li rel="/2019/03/05/Docker-部署/index.html" class="item ">
                <a href="/" title="首页" class="icon-home">&nbsp;首页</a>
            </li>
            
            <li rel="/2019/03/05/Docker-部署/index.html" class="item ">
                <a href="/about/" title="关于" class="icon-about">&nbsp;关于</a>
            </li>
            
            <li rel="/2019/03/05/Docker-部署/index.html" class="item ">
                <a href="/comment/" title="留言" class="icon-comment">&nbsp;留言</a>
            </li>
            
        </ul>
        <div class="profile clearfix">
            <div class="feeds fl">
                
                
                <p class="links">
                    
                        <a href="https://github.com/starryming" target="_blank">Github</a>
                        |
                    
                        <a href="http://ljmstarry.gitee.io" target="_blank">Hosted by Coding Pages</a>
                        
                    
                </p>
                <p class="sns">
                    
                        <a href="http://weibo.com/" class="sinaweibo" target="_blank"><b>■</b> 新浪微博</a>
                    
                        <a href="https://www.facebook.com/" class="qqweibo" target="_blank"><b>■</b> Facebook</a>
                    
                    <a href="javascript: void(0);" class="wechat">
                        <b>■</b>
                        公众号
                        <span class="popover">
                            <img src="/img/wechat_mp.jpg" width="120" height="120" alt="我的微信订阅号">
                            <i class="arrow"></i>
                        </span>
                    </a>
                </p>
                
            </div>
            <div class="avatar fr">
                <img src="/img/timg.jpg" alt="avatar" title="Jim">
            </div>
        </div>
    </section>
</header>


    <!-- 博客正文 -->
    <div class="container body clearfix">
        <section class="content">
            <div class="content-main widget">
                <!-- 文章页 -->
<!-- 文章 -->
<article class="post article">
    <header class="text-center">
        <h3 class="post-title"><span>Docker 部署</span></h3>
    </header>
    <p class="post-meta text-center">
        Jim 发表于
        <time datetime="2019-03-05T06:40:17.000Z">2019-03-05</time>
    </p>
    <div class="post-content">
        <p>在云服务器上、centos7，使用docker容器来搭建各种服务。</p>
<ul>
<li>docker安装</li>
<li>redis</li>
<li>mysql 主从</li>
<li>rabbitmq</li>
<li>zookeeper</li>
</ul>
<a id="more"></a>
<h2 id="Dockers命令"><a href="#Dockers命令" class="headerlink" title="Dockers命令"></a>Dockers命令</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"># 镜像</span><br><span class="line">docker images  <span class="comment">// 查看</span></span><br><span class="line">docker rmi [images id]  <span class="comment">// 删除</span></span><br><span class="line"></span><br><span class="line"># 容器</span><br><span class="line">docker ps  <span class="comment">// 查看</span></span><br><span class="line">docker stop [container id]	<span class="comment">// 停止</span></span><br><span class="line">docker rm [container id]  <span class="comment">// 删除</span></span><br></pre></td></tr></table></figure>
<hr>
<h2 id="2019-1-7-docker安装-view"><a href="#2019-1-7-docker安装-view" class="headerlink" title="2019/1/7    docker安装:   view"></a>2019/1/7    <strong>docker安装:</strong>   <a href="https://blog.csdn.net/u010046908/article/details/79553227" target="_blank" rel="noopener">view</a></h2><p>(centos需要7.2以上)</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">uname -r 	<span class="comment">// Docker要求Linux系统的内核版本高与3.10，所以安装前通过命令检查内核版本</span></span><br><span class="line">sudo yum update		<span class="comment">// 更新yum</span></span><br><span class="line">    </span><br><span class="line">sudo yum install -y yum-utils device-mapper-persistent-data lvm2	<span class="comment">// 安装需要的软件包</span></span><br><span class="line">sudo yum-config-manager --add-repo https:<span class="comment">//download.docker.com/linux/centos/docker-ce.repo		// 设置docker的yum源</span></span><br><span class="line">sudo yum install docker-ce	<span class="comment">// 安装</span></span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">sudo systemctl start docker		// 启动</span><br><span class="line">sudo systemctl enable docker	// 开机自启</span><br><span class="line"></span><br><span class="line">docker version	// 检查安装成功</span><br></pre></td></tr></table></figure>
<h2 id="2019-1-10-docker安装mysql-view"><a href="#2019-1-10-docker安装mysql-view" class="headerlink" title="2019/1/10    docker安装mysql   view"></a>2019/1/10    <strong>docker安装mysql</strong>   <a href="https://www.cnblogs.com/sweetchildomine/p/7814692.html" target="_blank" rel="noopener">view</a></h2><p>  <strong>- 数据卷配置</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">mkdir /docker</span><br><span class="line">mkdir /docker/mysql</span><br><span class="line">mkdir /docker/mysql/data</span><br><span class="line">mkdir /docker/mysql/mysql-files <span class="comment">//安装mysql8.0才需要这个文件夹，5.7不需要</span></span><br><span class="line">vim /docker/mysql/my.cnf</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//下面的内容输入到my.cnf中</span></span><br><span class="line">[mysqld]</span><br><span class="line">user=mysql</span><br><span class="line">character-set-server=utf8</span><br><span class="line">default_authentication_plugin=mysql_native_password</span><br><span class="line">table_definition_cache=<span class="number">400</span></span><br><span class="line">[client]</span><br><span class="line"><span class="keyword">default</span>-character-set=utf8</span><br><span class="line">[mysql]</span><br><span class="line"><span class="keyword">default</span>-character-set=utf8</span><br></pre></td></tr></table></figure>
  <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">sudo docker pull mysql:<span class="number">5.7</span>.24	<span class="comment">// 拉取镜像</span></span><br><span class="line">     </span><br><span class="line">docker run -d --privileged=<span class="keyword">true</span> -p <span class="number">3306</span>:<span class="number">3306</span> -v /docker/mysql/my.cnf:/etc/mysql/my.cnf -v /docker/mysql/data:/<span class="keyword">var</span>/lib/mysql -e MYSQL_ROOT_PASSWORD=password --name mysql mysql:<span class="number">5.7</span>.24</span><br><span class="line"></span><br><span class="line">sudo docker ps	<span class="comment">// 查看镜像运行</span></span><br></pre></td></tr></table></figure>
  <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">systemctl start firewalld	<span class="comment">// 开启防火墙</span></span><br><span class="line">sudo firewall-cmd --add-port=<span class="number">3306</span>/tcp	<span class="comment">// 防火墙开发端口</span></span><br><span class="line">    </span><br><span class="line"><span class="comment">/*sudo systemctl stop firewalld	 关闭防火墙 ——&gt; 可能被入侵	*/</span></span><br><span class="line">      </span><br><span class="line">docker exec -it mysql bash	<span class="comment">// docker进入mysql容器</span></span><br><span class="line">mysql -u root -p<span class="string">'password'</span> <span class="comment">// 然后给mysql设置权限</span></span><br><span class="line">      </span><br><span class="line">  </span><br><span class="line"><span class="comment">// 这样就可以在外面用navicate访问了</span></span><br></pre></td></tr></table></figure>
<hr>
<h2 id="2019-1-11-mysql主从复制-view"><a href="#2019-1-11-mysql主从复制-view" class="headerlink" title="2019/1/11    mysql主从复制   view"></a>2019/1/11    mysql主从复制   <a href="https://blog.csdn.net/deeplearnings/article/details/78398526" target="_blank" rel="noopener">view</a></h2><h3 id="主配置"><a href="#主配置" class="headerlink" title="主配置:"></a><strong>主配置:</strong></h3><h4 id="1、主服务my-cnf配置"><a href="#1、主服务my-cnf配置" class="headerlink" title="1、主服务my.cnf配置"></a>1、主服务my.cnf配置</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 对my.cnf配置  上述docker安装配置时，已经提前配置</span></span><br><span class="line">[mysqld]</span><br><span class="line">log-bin=mysql-bin   <span class="comment">//[必须]启用二进制日志</span></span><br><span class="line">server-id=<span class="number">1</span>      <span class="comment">//[必须]服务器唯一ID，默认是1，一般取IP最后一段</span></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">service mysql restart <span class="comment">// 重启服务</span></span><br></pre></td></tr></table></figure>
<h4 id="2、授权slave账号"><a href="#2、授权slave账号" class="headerlink" title="2、授权slave账号"></a>2、授权slave账号</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 主服务器上建立帐户并授权slave</span></span><br><span class="line">GRANT replication slave ON *.* TO <span class="string">'slave'</span>@<span class="string">'%'</span> IDENTIFIED BY <span class="string">'password'</span>; </span><br><span class="line"></span><br><span class="line"></span><br><span class="line">show variables like <span class="string">'server_id'</span>;  <span class="comment">// 查看server_id</span></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">+---------------+-------+</span></span><br><span class="line"><span class="comment">| Variable_name | Value |</span></span><br><span class="line"><span class="comment">+---------------+-------+</span></span><br><span class="line"><span class="comment">| server_id     | 1     |</span></span><br><span class="line"><span class="comment">+---------------+-------+</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"></span><br><span class="line">show master status;	 <span class="comment">// 查看二进制日志 log-bin=mysql-bin 没配置将查询为空 配置从服务器要用</span></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">+------------------+----------+--------------+------------------+-------------------+</span></span><br><span class="line"><span class="comment">| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |</span></span><br><span class="line"><span class="comment">+------------------+----------+--------------+------------------+-------------------+</span></span><br><span class="line"><span class="comment">| mysql-bin.000001 |      154 |              |                  |                   |</span></span><br><span class="line"><span class="comment">+------------------+----------+--------------+------------------+-------------------+</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/* 注：执行完此步骤后不要再操作主服务器MYSQL，防止主服务器状态值变化 */</span></span><br></pre></td></tr></table></figure>
<h3 id="从配置"><a href="#从配置" class="headerlink" title="从配置:"></a><strong>从配置:</strong></h3><h4 id="1、my-cnf基本配置"><a href="#1、my-cnf基本配置" class="headerlink" title="1、my.cnf基本配置"></a><strong>1、my.cnf基本配置</strong></h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 对my.cnf配置  上述docker安装配置时，已经提前配置</span></span><br><span class="line">[mysqld]</span><br><span class="line">server-id=<span class="number">2</span>      <span class="comment">//[必须]服务器唯一ID，默认是1，一般取IP最后一段</span></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">service mysql restart <span class="comment">// 重启服务</span></span><br></pre></td></tr></table></figure>
<h4 id="2、从服务slave配置"><a href="#2、从服务slave配置" class="headerlink" title="2、从服务slave配置"></a><strong>2、从服务slave配置</strong></h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">show variables like <span class="string">'server_id'</span>;  <span class="comment">// 查看server_id,预防配置未生效  server_id重复</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 从服务器配置 ： 注意不要断开，308数字前后无单引号。</span></span><br><span class="line">change master to master_host=<span class="string">'云服务ip'</span>, master_user=<span class="string">'slave'</span>, master_password=<span class="string">'password'</span>,master_log_file=<span class="string">'mysql-bin.000001'</span>,master_log_pos=<span class="number">154</span>;</span><br><span class="line"></span><br><span class="line">start slave;    <span class="comment">//启动从服务器复制功能</span></span><br></pre></td></tr></table></figure>
<h4 id="3、检查从服务器功能状态"><a href="#3、检查从服务器功能状态" class="headerlink" title="3、检查从服务器功能状态"></a>3、检查从服务器功能状态</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">show slave status\G</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">   *************************** 1. row ***************************</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">              Slave_IO_State: Waiting for master to send event</span></span><br><span class="line"><span class="comment">              Master_Host: ***  //主服务器地址</span></span><br><span class="line"><span class="comment">              Master_User: slave   //授权帐户名，尽量避免使用root</span></span><br><span class="line"><span class="comment">              Master_Port: 3306    //数据库端口，部分版本没有此行</span></span><br><span class="line"><span class="comment">              Connect_Retry: 60</span></span><br><span class="line"><span class="comment">              Master_Log_File: mysql-bin.000001</span></span><br><span class="line"><span class="comment">              Read_Master_Log_Pos: 600     //#同步读取二进制日志的位置，大于等于Exec_Master_Log_Pos</span></span><br><span class="line"><span class="comment">              Relay_Log_File: DESKTOP-6EUBVFN-relay-bin.000002</span></span><br><span class="line"><span class="comment">              Relay_Log_Pos: 320</span></span><br><span class="line"><span class="comment">              Relay_Master_Log_File: mysql-bin.000001</span></span><br><span class="line"><span class="comment">              Slave_IO_Running: Yes    //此状态必须YES</span></span><br><span class="line"><span class="comment">              Slave_SQL_Running: Yes     //此状态必须YES</span></span><br><span class="line"><span class="comment">                    ......</span></span><br><span class="line"><span class="comment">注：Slave_IO及Slave_SQL进程必须正常运行，即YES状态，否则都是错误的状态(如：其中一个NO均属错误)。</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>
<hr>
<h2 id="2019-1-10-docker安装redis-view"><a href="#2019-1-10-docker安装redis-view" class="headerlink" title="2019/1/10  docker安装redis    view"></a>2019/1/10  <strong>docker安装redis</strong>    <a href="https://blog.csdn.net/woniu211111/article/details/80970560" target="_blank" rel="noopener">view</a></h2><h3 id="数据卷配置"><a href="#数据卷配置" class="headerlink" title="数据卷配置"></a>数据卷配置</h3>  <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">mkdir /docker</span><br><span class="line">mkdir /docker/redis</span><br><span class="line">mkdir /docker/redis/conf</span><br><span class="line">mkdir /docker/redis/data</span><br><span class="line">   </span><br><span class="line">  </span><br><span class="line">touch /docker/redis/conf/redis.conf  <span class="comment">//创建redis.conf配置文件</span></span><br><span class="line">  </span><br><span class="line"><span class="comment">/*	redis.conf文件内容自行添加：</span></span><br><span class="line"><span class="comment">  	切记注释掉：#daemonize yes 否则无法启动容器</span></span><br><span class="line"><span class="comment">  	重要话说三遍：注释掉#daemonize yes，注释掉#daemonize yes，注释掉#daemonize yes</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>
<h3 id="镜像安装"><a href="#镜像安装" class="headerlink" title="镜像安装"></a>镜像安装</h3>  <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">docker pull redis <span class="comment">// 拉取镜像</span></span><br><span class="line">docker run -d --privileged=<span class="keyword">true</span> -p <span class="number">6379</span>:<span class="number">6379</span> -v /docker/redis/conf/redis.conf:/etc/redis/redis.conf -v /docker/redis/data:/data --name redistest2 redis:<span class="number">4.0</span> redis-server /etc/redis/redis.conf --appendonly yes</span><br><span class="line">  </span><br><span class="line"><span class="comment">/* 命令说明：</span></span><br><span class="line"><span class="comment">    privileged=true ：容器内的root拥有真正root权限，否则容器内root只是外部普通用户权限</span></span><br><span class="line"><span class="comment">    -p 6379:6379 ： 将容器的6379端口映射到主机的6379端口</span></span><br><span class="line"><span class="comment">    -v /docker/redis/conf/redis.conf:/etc/redis/redis.conf ：映射配置文件</span></span><br><span class="line"><span class="comment">    -v /docker/redis/data:/data ：映射数据目录</span></span><br><span class="line"><span class="comment">    redis-server /etc/redis/redis.conf ：指定配置文件启动redis-server进程</span></span><br><span class="line"><span class="comment">    --appendonly yes ：开启数据持久化</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line">      </span><br><span class="line">docker ps</span><br><span class="line">  </span><br><span class="line">docker exec -ti <span class="string">'Container Id'</span> redis-cli  <span class="comment">// docker进入redis</span></span><br></pre></td></tr></table></figure>
<hr>
<h2 id="2019-1-10-docker安装rabbitMq-view"><a href="#2019-1-10-docker安装rabbitMq-view" class="headerlink" title="2019/1/10    docker安装rabbitMq:    view"></a>2019/1/10    <strong>docker安装rabbitMq:</strong>    <a href="https://www.jianshu.com/p/c40166cb4e86" target="_blank" rel="noopener">view</a></h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker pull rabbitmq:management  <span class="comment">// 拉取镜像</span></span><br><span class="line">docker run -d --name rabbitmq --publish <span class="number">5671</span>:<span class="number">5671</span> --publish <span class="number">5672</span>:<span class="number">5672</span> --publish <span class="number">4369</span>:<span class="number">4369</span> --publish <span class="number">25672</span>:<span class="number">25672</span> --publish <span class="number">15671</span>:<span class="number">15671</span> --publish <span class="number">15672</span>:<span class="number">15672</span> rabbitmq:management		<span class="comment">// 启动容器</span></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 防火墙开放端口</span></span><br><span class="line">sudo firewall-cmd --add-port=<span class="number">5672</span>/tcp</span><br><span class="line">sudo firewall-cmd --add-port=<span class="number">15672</span>/tcp</span><br><span class="line"></span><br><span class="line"><span class="comment">// 浏览器：http://ip:15672/#/</span></span><br></pre></td></tr></table></figure>
<h3 id="设置账户password，因为guest默认password不允许外部ip登陆"><a href="#设置账户password，因为guest默认password不允许外部ip登陆" class="headerlink" title="- 设置账户password，因为guest默认password不允许外部ip登陆"></a>- 设置账户password，因为guest默认password不允许外部ip登陆</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it rabbitmq bash</span><br><span class="line"># 这里的admin可以替换成你的用户名和password</span><br><span class="line">rabbitmqctl add_user admin admin</span><br><span class="line">rabbitmqctl set_user_tags admin administrator</span><br></pre></td></tr></table></figure>
<hr>
<h2 id="2019-1-12-docker安装zookeeper"><a href="#2019-1-12-docker安装zookeeper" class="headerlink" title="2019/1/12   docker安装zookeeper"></a>2019/1/12   <strong>docker安装zookeeper</strong></h2><h3 id="1、数据卷"><a href="#1、数据卷" class="headerlink" title="1、数据卷"></a>1、数据卷</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">mkdir /docker/zookeeper</span><br><span class="line">mkdir /docker/zookeeper/data</span><br><span class="line">vim /docker/zookeeper/zoo.cfg</span><br><span class="line"><span class="comment">/* 配置内容</span></span><br><span class="line"><span class="comment">clientPort=2181</span></span><br><span class="line"><span class="comment">dataDir=/data</span></span><br><span class="line"><span class="comment">dataLogDir=/datalog</span></span><br><span class="line"><span class="comment">tickTime=2000</span></span><br><span class="line"><span class="comment">initLimit=5</span></span><br><span class="line"><span class="comment">syncLimit=2</span></span><br><span class="line"><span class="comment">autopurge.snapRetainCount=3</span></span><br><span class="line"><span class="comment">autopurge.purgeInterval=0</span></span><br><span class="line"><span class="comment">maxClientCnxns=60</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>
<h3 id="2、运行"><a href="#2、运行" class="headerlink" title="2、运行"></a>2、运行</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d --privileged=<span class="keyword">true</span> -p <span class="number">2181</span>:<span class="number">2181</span> -v /docker/zookeeper/zoo.cfg:/conf/zoo.cfg -v /docker/zookeeper/data:/data --name zookeeper zookeeper:latest</span><br></pre></td></tr></table></figure>
<hr>
<h2 id="2019-1-14-docker-搭建zookeeper集群"><a href="#2019-1-14-docker-搭建zookeeper集群" class="headerlink" title="2019/1/14  docker 搭建zookeeper集群"></a>2019/1/14  <strong>docker 搭建zookeeper集群</strong></h2><h3 id="安装docker-compose"><a href="#安装docker-compose" class="headerlink" title="安装docker-compose"></a>安装docker-compose</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">sudo curl -L https:<span class="comment">//github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose</span></span><br><span class="line"></span><br><span class="line">sudo chmod +x /usr/local/bin/docker-compose</span><br><span class="line"></span><br><span class="line">docker-compose --version</span><br></pre></td></tr></table></figure>
<h3 id="yml搭建zookeeper集群"><a href="#yml搭建zookeeper集群" class="headerlink" title="yml搭建zookeeper集群"></a>yml搭建zookeeper集群</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">vim docker-compose.yml</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">version: '3.1'</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">services:</span></span><br><span class="line"><span class="comment">  zoo1:</span></span><br><span class="line"><span class="comment">    image: zookeeper</span></span><br><span class="line"><span class="comment">    restart: always</span></span><br><span class="line"><span class="comment">    hostname: zoo1</span></span><br><span class="line"><span class="comment">    ports:</span></span><br><span class="line"><span class="comment">      - 2181:2181</span></span><br><span class="line"><span class="comment">    environment:</span></span><br><span class="line"><span class="comment">      ZOO_MY_ID: 1</span></span><br><span class="line"><span class="comment">      ZOO_SERVERS: server.1=0.0.0.0:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">  zoo2:</span></span><br><span class="line"><span class="comment">    image: zookeeper</span></span><br><span class="line"><span class="comment">    restart: always</span></span><br><span class="line"><span class="comment">    hostname: zoo2</span></span><br><span class="line"><span class="comment">    ports:</span></span><br><span class="line"><span class="comment">      - 2182:2181</span></span><br><span class="line"><span class="comment">    environment:</span></span><br><span class="line"><span class="comment">      ZOO_MY_ID: 2</span></span><br><span class="line"><span class="comment">      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zoo3:2888:3888</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">  zoo3:</span></span><br><span class="line"><span class="comment">    image: zookeeper</span></span><br><span class="line"><span class="comment">    restart: always</span></span><br><span class="line"><span class="comment">    hostname: zoo3</span></span><br><span class="line"><span class="comment">    ports:</span></span><br><span class="line"><span class="comment">      - 2183:2181</span></span><br><span class="line"><span class="comment">    environment:</span></span><br><span class="line"><span class="comment">      ZOO_MY_ID: 3</span></span><br><span class="line"><span class="comment">      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=0.0.0.0:2888:3888</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker-compose up -d</span><br></pre></td></tr></table></figure>
    </div>
    <p class="post-meta">
        <span class="post-cat">分类：
            <a class="cat-link" href="/categories/linus/">linus</a>
        </span>
        <span class="post-tags">
            标签：
            
    
        <a href="/tags/linus/" title="linus">linus</a> / 
    
        <a href="/tags/Docker/" title="Docker">Docker</a>
    

        </span>
    </p>
</article>
<!-- 分享按钮 -->

  <div class="article-share clearfix text-center">
    <div class="share-area">
      <span class="share-txt">分享到：</span>
      <a href="javascript: window.open('http://service.weibo.com/share/share.php?url=' + encodeURIComponent(location.href) + '&title=' + document.title + '&language=zh_cn');" class="share-icon weibo"></a>
      <a href="javascript: alert('请复制链接到微信并发送');" class="share-icon wechat"></a>
      <a href="javascript: window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + encodeURIComponent(location.href) + '&title=' + document.title);" class="share-icon qqzone"></a>
      <a href="javascript: window.open('http://connect.qq.com/widget/shareqq/index.html?url=' + encodeURIComponent(location.href) + '&desc=Jim个人博客&title=' + document.title + '&callback=' + encodeURIComponent(location.href));" class="share-icon qq"></a>
      <a href="javascript: window.open('http://shuo.douban.com/!service/share?href=' + encodeURIComponent(location.href) + '&name=' + document.title + '&text=' + document.title);" class="share-icon douban"></a>
    </div>
  </div>


<!-- 上一篇/下一篇 -->

<div class="article-nav clearfix">
    
    <span class="prev fl">
        上一篇<br>
        <a href="/2019/03/05/Nginx服务器搭建/">
            
                Nginx服务器搭建
            
        </a>
    </span>
    

    
    <span class="next fr">
        下一篇<br>
        <a href="/2019/03/05/hello-world/">
            
                Hello World
            
        </a>
    </span>
    
</div>

<!-- 文章评论 -->

  <script src="/js/comment.js"></script>
  <div id="comments" class="comment">
    <!--
    <div class="sign-bar">
      GitHub 已登录!
      <span class="sign-link">登出</span>
    </div>
    <section class="box">
      <div class="com-avatar"><img src="/img/jelon.jpg" alt="avatar"></div>
      <div class="com-text">
        <div class="main">
          <textarea class="text-area-edited show" placeholder="欢迎评论！"></textarea>
          <div class="text-area-preview"></div>
        </div>
        <div class="switch">
          <div class="switch-item on">编辑</div>
          <div class="switch-item">预览</div>
        </div>
        <div class="button">提交</div>
      </div>
    </section>
    <section class="tips">注：评论支持 markdown 语法！</section>
    <section class="list-wrap">
      <ul class="list">
        <li>
          <div class="user-avatar">
            <a href="/">
              <img src="/img/jelon.jpg" alt="user-avatar">
            </a>
          </div>
          <div class="user-comment">
            <div class="user-comment-header">
              <span class="post-name">张德龙</span>
              <span class="post-time">2017年12月12日</span>
              <span class="like liked">已赞</span>
              <span class="like-num">2</span>
            </div>
            <div class="user-comment-body">333333</div>
          </div>
        </li>
        <li>
          <div class="user-avatar">
            <a href="/">
              <img src="/img/jelon.jpg" alt="user-avatar">
            </a>
          </div>
          <div class="user-comment">
            <div class="user-comment-header">
              <span class="post-name">刘德华</span>
              <span class="post-time">2017年12月12日</span>
              <span class="like">点赞</span>
              <span class="like-num">2</span>
            </div>
            <div class="user-comment-body">vvvvv</div>
          </div>
        </li>
      </ul>
      <div class="page-nav">
        <a href="javascript: void(0);" class="item">1</a>
        <a href="javascript: void(0);" class="item">2</a>
        <a href="javascript: void(0);" class="item current">3</a>
      </div>
    </section>
    -->
  </div>
  <script>
  JELON.Comment({
    container: 'comments',
    label: 'Docker-部署' || '2019/03/05/Docker-部署/',
    owner: 'your_github_id',
    repo: 'your_blog_comments',
    clientId: 'your_client_id',
    clientSecret: 'your_client_secret'
  });
  </script>


            </div>

        </section>
        <!-- 侧栏部分 -->
<aside class="sidebar">
    <section class="widget">
        <h3 class="widget-hd"><strong>文章分类</strong></h3>
        <!-- 文章分类 -->
<ul class="widget-bd">
    
    <li>
        <a href="/categories/linus/">linus</a>
        <span class="badge">(4)</span>
    </li>
    
    <li>
        <a href="/categories/technology/">technology</a>
        <span class="badge">(8)</span>
    </li>
    
    <li>
        <a href="/categories/Reading/">Reading</a>
        <span class="badge">(13)</span>
    </li>
    
    <li>
        <a href="/categories/others/">others</a>
        <span class="badge">(1)</span>
    </li>
    
    <li>
        <a href="/categories/linus/technology/">technology</a>
        <span class="badge">(1)</span>
    </li>
    
    <li>
        <a href="/categories/mysql/">mysql</a>
        <span class="badge">(1)</span>
    </li>
    
    <li>
        <a href="/categories/mysql/technology/">technology</a>
        <span class="badge">(1)</span>
    </li>
    
</ul>
    </section>

    
    <section class="widget">
        <h3 class="widget-hd"><strong>热门标签</strong></h3>
        <!-- 文章标签 -->
<div class="widget-bd tag-wrap">
  
    <a class="tag-item" href="/tags/linus/" title="linus">linus (4)</a>
  
    <a class="tag-item" href="/tags/ngnix/" title="ngnix">ngnix (1)</a>
  
    <a class="tag-item" href="/tags/源码学习/" title="源码学习">源码学习 (2)</a>
  
    <a class="tag-item" href="/tags/阅读/" title="阅读">阅读 (13)</a>
  
    <a class="tag-item" href="/tags/Thinking-In-Java/" title="Thinking In Java">Thinking In Java (5)</a>
  
    <a class="tag-item" href="/tags/java/" title="java">java (3)</a>
  
    <a class="tag-item" href="/tags/technology/" title="technology">technology (1)</a>
  
    <a class="tag-item" href="/tags/springBoot/" title="springBoot">springBoot (2)</a>
  
    <a class="tag-item" href="/tags/设计模式/" title="设计模式">设计模式 (3)</a>
  
    <a class="tag-item" href="/tags/test/" title="test">test (1)</a>
  
    <a class="tag-item" href="/tags/Effective-Java/" title="Effective Java">Effective Java (8)</a>
  
    <a class="tag-item" href="/tags/mysql/" title="mysql">mysql (2)</a>
  
    <a class="tag-item" href="/tags/Docker/" title="Docker">Docker (1)</a>
  
</div>
    </section>
    

    

    
    <!-- 友情链接 -->
    <section class="widget">
        <h3 class="widget-hd"><strong>友情链接</strong></h3>
        <!-- 文章分类 -->
<ul class="widget-bd">
    
        <li>
            <a href="https://www.bilibili.com" target="_blank" title="bilibili">哔哩哔哩</a>
        </li>
    
        <li>
            <a href="https://www.baidu.com" target="_blank" title="百度搜索">百度</a>
        </li>
    
</ul>
    </section>
    
</aside>
<!-- / 侧栏部分 -->
    </div>

    <!-- 博客底部 -->
    <footer class="footer">
    &copy;
    
        2016-2020
    

    <a href="/">Jim Loves You</a>
</footer>
<div class="back-to-top" id="JELON__backToTop" title="返回顶部">返回顶部</div>

    <!--博客js脚本 -->
    <!-- 这里放网站js脚本 -->
<script src="/js/main.js"></script>
</body>
</html>